#include "symbolstable.h"
#include "utills.h"

#include <sstream>

namespace CCompiler
{
    std::string SymTable::genAnonName()
    {
        std::ostringstream stream;
        stream << anon_type_counter_++;
        return stream.str();
    }  

    void Symbol::print(std::ostream &stream, int ident)
    {
        makeIDent(stream, ident);
        stream << name_ ;
    }

    void SymVariable::print(std::ostream &stream, int ident)
    {
        makeIDent(stream, ident);
        stream << type_->getName();
        Symbol::print(stream << ' ', 0);
    }

    void SymFunction::print(std::ostream &stream, int ident)
    {
        makeIDent(stream, ident);
        stream << ftype_->genFuntionTypeName(' ' + getName());
    }

    void SymAlias::print(std::ostream &stream, int ident)
    {
        makeIDent(stream, ident);
        stream << "typedef " << type_->getName() << ' ' << getName();
    }

    void SymTypeStruct::print(std::ostream &stream, int ident)
    {
        makeIDent(stream, ident);
        stream << "struct " << getName() << '\n';
        makeIDent(stream, ident);
        stream << '{' << '\n';
        tbl_.print(stream, ident + 1);
        makeIDent(stream, ident);
        stream << '}';
    }

	void SymTypeArray::print(std::ostream &stream, int ident)
	{
		makeIDent(stream, ident);
        stream << getPointed()->getName() << '[' << size_ << ']';
	}
}